var local = "http://47.104.10.151";
var apiUrl = local + ":8080";
var AjaxIO = {
    _getUrl: function (action) {
        return apiUrl + action;
    },
    _ajax: function (url, method, param, callback, fail_callback) {

        if (callback == undefined) {
            callback = param;
        }
        var token = localStorage.getItem('token');
        var headers = undefined;
        if (token != null) {
            // headers = {'Authorization': 'Basic ' + token};
            param.Authorization = token;
        }
        $.ajax({
            url: this._getUrl(url),
            data: param,
            datatype: 'json',
            // headers:headers,
            method: method,
            statusCode: {
                401: function (result) {
                },
                404: function () {
                },
                201: function () {
                },
                202: function () {

                }
            },
            success: callback,
            error: fail_callback
        });
    },

    get: function (url, param, callback, fail_callback) {
        this._ajax(url, "GET", param, callback, fail_callback);
    },

    post: function (url, param, callback, fail_callback) {
        this._ajax(url, "POST", param, callback, fail_callback)
    },

    put: function (url, param, callback, fail_callback) {
        this._ajax(url, "PUT", param, callback, fail_callback);
    },

    delete: function (url, param, callback, fail_callback) {
        this._ajax(url, "DELETE", param, callback, fail_callback)

    }
};

function getParamer(paramer) {

    var url = window.location.href.split("?")[1];
    /*获取url里"?"后面的值*/
    if (url.indexOf("&") > 0) {                                      /*判断是否是一个参数还是多个参数*/
        urlParamArry = url.split("&");
        /*分开每个参数，并放到数组里*/
        for (var i = 0; i < urlParamArry.length; i++) {
            var paramerName = urlParamArry[i].split("=");
            /*把每个参数名和值分开，并放到数组里*/
            if (paramer == paramerName[0]) {                     /*匹配输入的参数和数组循环出来的参数是否一样*/
                return paramerName[1];
                /*返回想要的参数值*/
            }
        }
    } else {                                                              /*判断只有个参数*/
        var paramerValue = url.split("=")[1];
        return paramerValue;
    }

}

function getData() {
    var order_id = getParamer("order_id")
    param = {
        "order_Id": order_id
    };
    AjaxIO.post("/importOrder/importOrder", param, function (result) {
        var d = result.data;
        $("#sell").val(d.sell_CompanyName);
        $("#num").val(order_id);
        $("#buy").val(d.buy_CompanyName);
        $("#date").val(result.timestamp);
        $("#id").val(d.keyId);
        $("#name").val(d.product_name);
        $("#brand").val(d.brand);
        $("#model").val(d.model_code);
        $("#size").val(d.size);
        $("#inventory").val(d.inventory);
        $("#danwei").val("元");
        $("#sigle_price").val(d.sigle_price);
        $("#totalprice").val(d.total_price);
        $("#notice").val(d.notice);

    })
}


$(document).ready(function () {
    getData();
});